const stateSource = {};

export default {
    namespaced: true,

    state: stateSource,

    mutations: {
        updateStateSource(state, { key, value, rootState, modules }) {
            rootState[modules][key] = value;
        },

        initCommonState(state) {
            for (let i in stateSource) {
                state[i] = stateSource[i];
            }
        }
    },

    actions: {
        setStateSource({ commit, rootState }, obj) {
            obj = { ...obj, ...{ rootState } };
            commit('updateStateSource', obj);
        },

        loopStateSource({ dispatch }, arr) {
            arr.forEach(item => {
                dispatch('setStateSource', item);
            });
        }
    }
};
